package com.caius.xiaohashu.auth.alarm;

import com.caius.framework.common.exception.BizException;
import com.caius.xiaohashu.auth.alarm.Impl.MailAlarmHelper;
import com.caius.xiaohashu.auth.alarm.Impl.SmsAlarmHelper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Caius
 * @description
 * @since Created in 2025-05-11
 */
@Configuration
@RefreshScope
public class AlarmConfig {

    @Value("${alarm.type}")
    private String alarmType;

    @Bean
    @RefreshScope
    public AlarmInterface alarmHelper() {
        if(StringUtils.equals("sms", alarmType)) {
            return new SmsAlarmHelper();
        } else if(StringUtils.equals("mail", alarmType)) {
            return new MailAlarmHelper();
        } else {
            throw new IllegalArgumentException("错误的告警类型...");
        }
    }
}
